import requests
from lxml import etree

if __name__ == '__main__':
    url = 'https://fz.58.com/ershoufang/?from=esf'
    # UA伪装: 将对应的User-Agent封装到一个字典中
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'
    }

    page_text = requests.get(url=url,headers=headers).text

    tree=etree.HTML(page_text)
    title_lst = tree.xpath('//div[@class="property-content-title"]/h3/@title')
    a_lst = tree.xpath('//div[@tongji_tag="fcpc_ersflist_gzcount"]/a/@href')
    for index in range(len(title_lst)):
        print(title_lst[index],"\t",a_lst[index])
